package io.renren.modules.back.controller;

import io.renren.common.annotation.SysLog;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.back.entity.AttributeCategoryEntity;
import io.renren.modules.back.service.AttributeCategoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.Map;

/**
 * 商品属性分类接口
 *
 * @author zzh
 * @email 862583291@qq.com
 * @date 2018年12月10日 上午10:40:10
 */
@RestController
@RequestMapping("/back/attributecategory")
public class AttributeCategoryController {

    @Autowired
    private AttributeCategoryService attributeCategoryService;

    /**
     * 查看列表
     */
    @GetMapping("/list")
    @RequiresPermissions("attributecategory:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = attributeCategoryService.queryPage(params);
        return R.ok().put("data", page);
    }

    /**
     * 查看信息
     */
    @GetMapping("/info/{id}")
    @RequiresPermissions("attributecategory:info")
    public R info(@PathVariable("id") Long id){
        AttributeCategoryEntity attributeCategory = attributeCategoryService.getById(id);
        return R.ok().put("data", attributeCategory);
    }

    /**
     * 保存
     */
    @SysLog("保存商品属性分类")
    @PostMapping("/save")
    @RequiresPermissions("attributecategory:save")
    public R save(@RequestBody AttributeCategoryEntity attributeCategory){
        ValidatorUtils.validateEntity(attributeCategory);
        attributeCategoryService.save(attributeCategory);
        return R.ok();
    }

    /**
     * 修改
     */
    @SysLog("修改商品属性分类")
    @PostMapping("/update")
    @RequiresPermissions("attributecategory:update")
    public R update(@RequestBody AttributeCategoryEntity attributeCategory){
        ValidatorUtils.validateEntity(attributeCategory);
        attributeCategoryService.updateById(attributeCategory);
        return R.ok();
    }

    /**
     * 删除
     */
    @SysLog("删除商品属性分类")
    @PostMapping("/delete")
    @RequiresPermissions("attributecategory:delete")
    public R delete(@RequestBody Long[] ids){
        attributeCategoryService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
